function ajax(ops = {}) {
    let { type = "get", success, error, url, data = {}, timeout = 100 } = ops;
    let str = "";
    for (let i in data) {
        str += `${i}=${data[i]}&`;
    }
    url = type === "get" ? url + "?" + str.slice(0, -1) : url;
    const xhr = new XMLHttpRequest();
    xhr.timeout = timeout;
    xhr.open(type, url, true);
    xhr.onload = function () {
        if (xhr.status === 200) {
            if (success) success(xhr.responseText);
        } else {
            if (error) error(xhr.status);
        }
    }
    xhr.ontimeout = function () {
        if (error) error("timeout");
        xhr.abort();
    }
    if (type === "post") {
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhr.send(str.slice(0, -1));
    } else {
        xhr.send();
    }
}